<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Company;

class CompanyController extends Controller
{
    public function __construct() {
        $this -> middleware('auth');
    }
    
    public function home() {
        $user = Auth::user();
        //dd($user);
        return view('csite.home', ['user' => $user]);
    }

    public function showCreate() {
        return view('csite.create');
    } 

    public function create(Request $request) {
        // dd($request);
        $this->validate($request, [
            'name' => 'required',
            'address' => 'required',
            'phone' => 'required',
            'software' => 'required'
        ]);
        
        $company = new Company;
        $company->name = $request->name;
        $company->address = $request->address;
        $company->phone = $request->phone;
        $company->softname = $request->software;
        $company->save();

        return back()->with('res', '注册成功');

    }

    public function list() {
        $companyies = Company::all();
        //return $companyies;
        //var_dump($companyies);
        return view('csite.list', ['companies'=>$companyies]);
    }

    public function showCharge() {
        return view('csite.charge');
    }

    public function search() {
        
    }
}
